<?php
class ml_model_dbIdGenerator extends Lib_datamodel_db 
{
    function __construct() {
        $db_config = ml_factory::load_standard_conf ( 'dbContent' );
        parent::__construct ( 'id_generator', $db_config ['id_generator'] );
    }
    
    /**
     * 生成内容资源ID
     *
     * @param int $id
     * @return bool
     */
    public function get_content_rid($uid , &$rid)
    {
        if($this->_generate_id('ml_content_id_gen'))
        {
            $rid = ml_tool_resid::make_resid($uid , ML_RESID_TYPE_CONTENT , $this->insert_id());
            return true;
        }
        else 
            return false;
    }
    /**
     * 生成用户动态自增ID
     *
     * @param unknown_type $id
     * @return unknown
     */
    public function get_userfeed_rid($uid , &$rid)
    {
        if($this->_generate_id('ml_userfeed_id_gen'))
        {
            $rid = ml_tool_resid::make_resid($uid , ML_RESID_TYPE_USERFEED , $this->insert_id());
            return true;
        }
        else 
            return false;
    }
    /**
     * 生成画报feed自增ID
     *
     * @param unknown_type $id
     * @return unknown
     */
    public function get_albumfeed_rid($album_id , &$rid)
    {
        if($this->_generate_id('ml_albumfeed_id_gen'))
        {
            $rid = ml_tool_resid::make_resid($album_id , ML_RESID_TYPE_ALBUMFEED , $this->insert_id());
            return true;
        }
        else
            return false;
    }
    /**
     * 生成画报feed自增ID
     *
     * @param unknown_type $id
     * @return unknown
     */
    public function get_albumreply_rid($album_id , &$rid)
    {
        if($this->_generate_id('ml_albumreply_id_gen'))
        {
            $rid = ml_tool_resid::make_resid($album_id , ML_RESID_TYPE_ALBUMREPLY , $this->insert_id());
            return true;
        }
        else
            return false;
    }
    private function _generate_id($table)
    {
        if(!$this->init_db())
            return false;
            
        $this->table = $table;
        if(!$this->replace(array('ticket' => 'a')))
            return false;
            
        $id = $this->insert_id();
        return true;
    }
}
?>